package cn.edu.hbpu.controller;

import cn.edu.hbpu.common.page.PageQueryBean;
import cn.edu.hbpu.common.page.PageQueryCondition;
import cn.edu.hbpu.pojo.Attend;
import cn.edu.hbpu.pojo.Student;
import cn.edu.hbpu.service.AttendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by yuwenteng on 2017/9/18.
 */
@Controller
@RequestMapping("attend")
public class AttendController {

    @Autowired
    private AttendService attendService;

    /**
     * @Author yuwenteng
     * @Date 2017/9/19 10:49
     * @Description 跳转到考勤数据页面
     */
    @RequestMapping("/showAttendPage")
    public String showAttendPage() {
        return "attend";
    }

    /**
     * @Author yuwenteng
     * @Date 2017/9/19 10:50
     * @Description 添加考勤签到数据到数据库
     */
    @RequestMapping("/signAttendance")
    @ResponseBody
    public String signAttendance(Attend attend) {
        attendService.signAttendance(attend);
        return "success";
    }

    /**
     * @Author yuwenteng
     * @Date 2017/9/20 11:01
     * @Description 查询分页考勤数据
     */
    @RequestMapping("/findAttendceInfo")
    @ResponseBody
    public PageQueryBean findAttendceInfo(PageQueryCondition pageQueryCondition, HttpSession session) {
        //通过session拿到用户信息
        Student student = (Student) session.getAttribute("stuInfo");
        //将前端页面传递过来的正则表达式拆成数组
        String[] rangeDate = pageQueryCondition.getRangeDate().split("/");
        //将数据封装到pageQueryCondition对象中
        pageQueryCondition.setStartDate(rangeDate[0]);
        pageQueryCondition.setEndDate(rangeDate[1]);
        pageQueryCondition.setSno(student.getSno());
        PageQueryBean pageQueryBean = attendService.findAttendceInfo(pageQueryCondition);
        return pageQueryBean;
    }
}
